﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Oracle.ManagedDataAccess.Client;
using ThanhTu.GNC.Media.KQXS.DataAccess.DO;
using ThanhTu.GNC.Media.KQXS.Common;

namespace ThanhTu.GNC.Media.KQXS.DataAccess.DAL
{
    public class CalendarDAL : BaseDAL
    {
        public CalendarDAL() : base() { }
        public List<CalendarDO> SelectAll_Calendar()
        {
            using (OracleCommand oraComm = new OracleCommand())
            {
                oraComm.CommandType = CommandType.StoredProcedure;
                oraComm.CommandText = "Calendar_PKG.GetAllCalendar";
                OracleParameter oraParam = null;

                oraParam = new OracleParameter("OUTRETURN", OracleDbType.RefCursor);
                oraParam.Direction = ParameterDirection.Output;
                oraComm.Parameters.Add(oraParam);

                using (DataSet ds = GetDataSet(oraComm))
                {
                    DataTable dt = null;
                    List<CalendarDO> vCalendarDOCollection = null;
                    DataRow dr = null;
                    CalendarDO vCalendarDO = null;

                    if (ds != null)
                    {
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];
                            vCalendarDOCollection = new List<CalendarDO>();

                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                dr = dt.Rows[i];
                                vCalendarDO = new CalendarDO();

                                if (!Convert.IsDBNull(dr["DATEAWARDS_ID"]))
                                { vCalendarDO.DATEAWARDS_ID = Convert.ToString(dr["DATEAWARDS_ID"]); }

                                if (!Convert.IsDBNull(dr["DATEAWARDS"]))
                                { vCalendarDO.DATEAWARDS = Utils.ToUTF8String((byte[])dr["DATEAWARDS"]); }

                                vCalendarDOCollection.Add(vCalendarDO);
                                dr = null;
                                vCalendarDO = null;
                            }

                            dt.Dispose();
                            dt = null;
                        }

                        ds.Dispose();
                    }
                    oraComm.Dispose();
                    oraParam = null;

                    return vCalendarDOCollection;
                }
            }
        }
    }
}
